// pages/duobao/cjRec/cjRec.js
import S_request from '../../../utils/requestService.js';
import CONFIG from '../../../config.js';
import * as utils from '../../../utils/util.js';
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuList: [{
        id: '1',
        name: "待开奖",
        hidden: false,
        color: 'orange'
      },
      {
        id: '2',
        name: "已开奖",
        hidden: true,
        color: 'black'
      }
    ],
    swiperCurrent: 0, //当前的位置
    cjList: [],
    cjData: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getCJRecord();
  },
  getCJRecord: function() {
    S_request.duobao.cjRecord((result) => {
      for (let i = 0; i < result.wait.length; i++) {
        let item = result.wait[i];
        item.open_time = utils.formatTime(item.open_time, 2);
        item.btnTitle = '等待开奖'
        item.btnStyle = 'background-color:#e42c2c;'
      }
      for (let i = 0; i < result.already.length; i++) {
        let item = result.already[i];
        item.open_time = utils.formatTime(item.open_time, 2);
        item.btnTitle = '已开奖'
        item.btnStyle = 'background-color:#9a9898;'
      }
      this.setData({
        cjData: result,
        cjList: result.wait
      })
    })
  },
  clickMenu: function(e) {
    let id = e.currentTarget.dataset.id;
    console.log(e.currentTarget.dataset.id);
    for (var i = 0; i < this.data.menuList.length; i++) {
      this.data.menuList[i]["hidden"] = true;
      this.data.menuList[i]["color"] = 'black';
    }
    this.data.menuList[id - 1]["hidden"] = false;
    this.data.menuList[id - 1]["color"] = 'orange';
    this.data.swiperCurrent = id - 1;
    let tempList = [];
    if (id == 1) {
      tempList = this.data.cjData.wait;
    } else {
      tempList = this.data.cjData.already;
    }
    this.setData({
      menuList: this.data.menuList,
      swiperCurrent: this.data.swiperCurrent,
      cjList: tempList
    })
  },
  changeCurrent: function(e) {
    console.log(e.detail);
    let current = e.detail.current;
    for (var i = 0; i < this.data.menuList.length; i++) {
      this.data.menuList[i]["hidden"] = true;
      this.data.menuList[i]["color"] = 'black';
    }
    this.data.menuList[current]["hidden"] = false;
    this.data.menuList[current]["color"] = 'orange';
    let tempList = [];
    if (current == 0) {
      tempList = this.data.cjData.wait;
    } else {
      tempList = this.data.cjData.already;
    }
    this.setData({
      menuList: this.data.menuList,
      cjList: tempList
    })
  },
  toDetail: function(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../detail/detail?id=' + id,
    })
  },
  //暂时不用
  chakan: function() {
    let id = e.currentTarget.dataset.id;
    let isKj = e.currentTarget.dataset.status0;
    let kjStatus = e.currentTarget.dataset.status;
    if (isKj == 0) { //等待开奖
      wx.navigateTo({
        url: '../detail/detail?id=' + id,
      })
    } else { //已开奖

    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    wx.showShareMenu({
      withShareTicket: true,
      success: function() {}
    });
    let obj = { 'pagepath': CONFIG.SHARE.pathDuobao }
    S_request.index.recordShare("-6", obj);
    return {
      title: CONFIG.SHARE.titleDuobao,
      path: CONFIG.SHARE.pathDuobao,
      imageUrl: CONFIG.SHARE.imagDuobao,
      success: res => { //新版不走回调
        console.log("分享成功")
      }
    }
  },
})